#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class Solution
{
public:
    //dp[i]表示从0...i，并且打劫了第i个房屋获得的最高金额
    //dp[i+1] = max(dp[j]+a[j])[j<i]
    int rob(vector<int> &nums)
    {
        vector<int> dp(nums.begin(), nums.end());
        int maxval = 0;
        for (int i = 0; i < dp.size(); ++i)
        {
            for (int j = max(0, i - 3); j < i - 1; ++j)
            {
                dp[i] = max(dp[i], dp[j] + nums[i]);
            }
            maxval = max(dp[i], maxval);
        }
        return maxval;
    }
};